package com.tongsys.server.utils;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class RtnUtils {
    //是否执行成功
    private Boolean success;
    //状态码
    private Integer code;
    //返回消息
    private String message;
    //返回数据
    private Map<String,Object> data=new HashMap<>();

    private RtnUtils(){}

    public static RtnUtils ok(){
        RtnUtils rtnUtils = new RtnUtils();
        rtnUtils.setSuccess(true);
        rtnUtils.setCode(RtnCode.SUCCESS);
        rtnUtils.setMessage("执行成功");
        return rtnUtils;
    }
    public static RtnUtils err(){
        RtnUtils rtnUtils = new RtnUtils();
        rtnUtils.setSuccess(false);
        rtnUtils.setCode(RtnCode.ERROR);
        rtnUtils.setMessage("执行失败");
        return rtnUtils;
    }

    public RtnUtils code(Integer code){
        this.setCode(code);
        return this;
    }

    public RtnUtils msg(String msg){
        this.setMessage(msg);
        return this;
    }
    public RtnUtils data(Map<String,Object> map){
        this.setData(map);
        return this;
    }
    public RtnUtils data(Object obj){
        this.data.put("item",obj);
        return this;
    }


}
